package com.hifar.test.report.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hifar.test.entrust.constant.ReportConsts;
import com.hifar.test.report.mapper.HfEnvReportRecordMapper;
import com.hifar.test.report.pojo.HfEnvReportRecord;
import com.hifar.test.report.service.IHfEnvReportRecordService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author zhuWeiWei
 * @description 报告流转记录
 * @date 2024/12/26 14:23
 */
@Service
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
public class HfEnvReportRecordServiceImpl extends ServiceImpl<HfEnvReportRecordMapper, HfEnvReportRecord> implements IHfEnvReportRecordService {
    @Override
    public void saveCreateRecord(String reportId) {
        this.saveRecord(reportId, ReportConsts.REPORT_OPT_TYPE_CREATE);
    }

    @Override
    public void saveSubmitRecord(String reportId) {
        this.saveRecord(reportId, ReportConsts.REPORT_OPT_TYPE_SUBMIT);
    }

    @Override
    public void saveExaminePassRecord(String reportId) {
        this.saveRecord(reportId, ReportConsts.REPORT_OPT_TYPE_EXAMINE_PASS);
    }

    @Override
    public void saveExamineRejectRecord(String reportId) {
        this.saveRecord(reportId, ReportConsts.REPORT_OPT_TYPE_EXAMINE_REJECT);
    }

    @Override
    public void saveApprovePassRecord(String reportId) {
        this.saveRecord(reportId, ReportConsts.REPORT_OPT_TYPE_APPROVE_PASS);
    }

    @Override
    public void saveApproveRejectRecord(String reportId) {
        this.saveRecord(reportId, ReportConsts.REPORT_OPT_TYPE_APPROVE_REJECT);
    }

    @Override
    public void saveRecord(String reportId, String reportOptType) {
        this.saveRecord(reportId, reportOptType, "");
    }

    @Override
    public void saveRecord(String reportId, String reportOptType, String remarks) {
        HfEnvReportRecord hfEnvReportRecord = new HfEnvReportRecord();
        hfEnvReportRecord.setReportId(reportId);
        hfEnvReportRecord.setOptType(reportOptType);
        hfEnvReportRecord.setRemarks(remarks);
        this.save(hfEnvReportRecord);
    }

    @Override
    public List<HfEnvReportRecord> listRecord(String reportId) {
        QueryWrapper<HfEnvReportRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
                .eq(HfEnvReportRecord::getReportId, reportId)
                .orderByAsc(HfEnvReportRecord::getCreateTime);
        return this.list(queryWrapper);
    }
}
